package com.edfu.core.commons.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.edfu.core.commons.beans.Rating;
import com.edfu.core.commons.persistence.entity.RatingEntity;

public class RatingBeanTransformer {

	public static RatingEntity transformRating(Rating rating) {
		RatingEntity ratingEntity = new RatingEntity();
		ratingEntity.setDescription(rating.getDescription());
		ratingEntity.setObjectId(rating.getObjectId());
		ratingEntity.setObjectType(rating.getObjectType());
		ratingEntity.setRatedOn(Calendar.getInstance().getTimeInMillis());
		ratingEntity.setScore(rating.getScore());
		
		return ratingEntity;
	}
	
	public static Rating transformRating(RatingEntity ratingEntity) {
		Rating rating = new Rating();
		rating.setDescription(ratingEntity.getDescription());
		rating.setId(ratingEntity.getId());
		rating.setObjectType(ratingEntity.getObjectType());
		rating.setObjectId(ratingEntity.getObjectId());
		rating.setRatedOn(new Date(ratingEntity.getRatedOn()));
		rating.setScore(ratingEntity.getScore());
		rating.setUserId(ratingEntity.getUser().getUserId());
		
		return rating;
	}

	public static List<Rating> transformRatings(List<RatingEntity> ratingEntities) {
		List<Rating> ratings = new ArrayList<Rating>();
		for (RatingEntity ratingEntity : ratingEntities) {
			ratings.add(transformRating(ratingEntity));
		}
		
		return ratings;
	}

}
